package com.protocolmeter.frame;

import com.protocolmeter.function.FrameFunction;

/**
 * @ClassName: BaseFrame
 * @Description: 水表帧结构
 * @author baozhijian
 * @date 2017年7月24日 下午4:30:33
 * @version V1.0
 */
public class Meterwater implements Meter {

	private String address;
	private String data;
	private String type;
	private String cs;

	public String getData() {
		return data;
	}

	public Meterwater(String address, int type) {
		this.address = address;
		this.type = String.valueOf(type);

		FrameFunction frameFunction = new FrameFunction();
		this.cs = frameFunction.Cs("68" + this.type + frameFunction.Reverse(this.address) + "0103901F00");
	}

	public Meterwater(String sentdata, String frame) {
		while (frame.substring(0, 2).equalsIgnoreCase("FE")) {
			frame = frame.substring(2);
		}
		this.address = frame.substring(4, 18);
		FrameFunction frameFunction = new FrameFunction();
		this.data = frameFunction.Reverse(frame.substring(28, 36));
	}

	@Override
	public String toString() {
		FrameFunction frameFunction = new FrameFunction();
		return "FEFEFE68" + this.type + frameFunction.Reverse(this.address) + "0103901F00" + this.cs + "16";
	}

	@Override
	public String Getdata() {
		return "901F-" + this.data;
	}

}
